package com.np.storage_demo1;

import androidx.appcompat.app.AppCompatActivity;

import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import com.np.storage_demo1.utils.PermissionX;

public class ContentProviderActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_content_provider);

        PermissionX.checkPermission(this, new String[]{android.Manifest.permission.READ_CONTACTS}, 1);

        Cursor cur = getContentResolver().query(Phone.CONTENT_URI, null, null, null, null);
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.adapter_contact_list, cur, new String[]{Phone.DISPLAY_NAME_PRIMARY, Phone.NUMBER}, new int[]{R.id.tv_name, R.id.tv_number});
        ListView lvContact = findViewById(R.id.lv_contact);
        lvContact.setAdapter(adapter);
    }
}